package operation;

import Dao.ReportDao;
import interfac.OrderOperation;
import pojo.MilkTeaProduct;

import java.util.Map;
import java.util.Scanner;

public class ShowDailyReportOparetion implements OrderOperation {
    @Override
    public void execute(Scanner scanner){
        ReportDao reportDao = new ReportDao();
        Map<String, Object> report = reportDao.generateDailySalesReport();

        System.out.println("----今日销售报告----");
        System.out.println("日期: " + report.get("date"));
        System.out.println("总销售额: " + report.get("total_sales") + "元");
        System.out.println("订单总数: " + report.get("orders_count"));

        Map<MilkTeaProduct, Integer> productSales = (Map<MilkTeaProduct, Integer>) report.get("product_sales");
        if (productSales != null && !productSales.isEmpty()) {
            System.out.println("产品销售详情:");
            for (Map.Entry<MilkTeaProduct, Integer> entry : productSales.entrySet()) {
                MilkTeaProduct product = entry.getKey();
                Integer quantitySold = entry.getValue();
                System.out.println("- " + product.getProduct_name() + ": " + quantitySold + "杯");
            }
        } else {
            System.out.println("没有产品销售记录。");
        }

        Double profit = (Double) report.get("profit");
        System.out.println("今日盈利: " + (profit != null ? String.format("%.2f", profit) : "0.00") + "元");
        System.out.println("-------------------");
    }

}
